#!/bin/bash

echo "此脚本会为您的机器的network进行静态地址转换"
sleep 2
ip=$(ifconfig ens33 | grep -w inet | awk '{print $2}')
netmask=$(ifconfig ens33 | grep -w inet | awk '{print $4}')
gateway=$(route -n | awk 'NR==3{print $2}')
dns=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')

sed -ri 's|dhcp|none|g' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPADDR=$ip" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NETMASK=$netmask" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "GATEWAY=$gateway" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "dns1=$dns" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "nameserver $dns" >> /etc/resolv.conf 
systemctl restart network
echo "完毕"
cat /etc/sysconfig/network-scripts/ifcfg-ens33

